package com.five.wisdomEat.service;

import com.five.wisdomEat.entity.ResponseMessage;
import com.five.wisdomEat.entity.RestaurantOrders;
import com.five.wisdomEat.mapper.RestaurantOrdersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RestaurantOrdersService {
    @Autowired
    private RestaurantOrdersMapper mapper;
    public ResponseMessage selectROrderListByBusiness(String bNumber){
        ResponseMessage message = new ResponseMessage();
        message.setMessage("查询成功");
        message.setSuccess(true);
        message.setData(mapper.selectROrderListByBusiness(bNumber));
        message.setTotal(message.getData().size());
        return message;
    }

    public ResponseMessage selectROrderListByStudent(String sNumber){
        ResponseMessage message = new ResponseMessage();
        message.setMessage("查询成功");
        message.setSuccess(true);
        message.setData(mapper.selectROrderListByStudent(sNumber));
        message.setTotal(message.getData().size());
        return message;
    }

    public ResponseMessage insertROrder(RestaurantOrders restaurantOrders){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.insertROrder(restaurantOrders)>0;
        if(flag){
            message.setMessage("添加成功");
            message.setSuccess(flag);

        }else {
            message.setMessage("添加失败");
            message.setSuccess(flag);
        }
        return message;
    }

    public ResponseMessage updateROrder(RestaurantOrders restaurantOrders){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.updateROrder(restaurantOrders)>0;
        if(flag){
            message.setMessage("更新成功");
            message.setSuccess(flag);
        }else {
            message.setMessage("更新失败");
            message.setSuccess(flag);
        }
        return message;
    }

    public ResponseMessage deleteROrder(String roNumber){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.deleteROrder(roNumber)>0;
        if(flag){
            message.setMessage("删除成功");
            message.setSuccess(flag);
        }else {
            message.setMessage("删除失败");
            message.setSuccess(flag);
        }
        return message;
    }

    public ResponseMessage selectROrderListByBusinessExample(RestaurantOrders restaurantOrders){
        ResponseMessage message = new ResponseMessage();
        message.setMessage("查询成功");
        message.setSuccess(true);
        message.setData(mapper.selectROrderListByBusinessExample(restaurantOrders));
        message.setTotal(message.getData().size());
        return message;
    }

    public ResponseMessage selectROrderListByStudentExample(RestaurantOrders restaurantOrders){
        ResponseMessage message = new ResponseMessage();
        message.setMessage("查询成功");
        message.setSuccess(true);
        message.setData(mapper.selectROrderListByStudentExample(restaurantOrders));
        message.setTotal(message.getData().size());
        return message;
    }

    public ResponseMessage selectOrdersCount(){
        ResponseMessage message = new ResponseMessage();
        message.setMessage("查询成功");
        message.setSuccess(true);
        message.setTotal(mapper.selectOrdersCount());
        return message;
    }

    public ResponseMessage confirmROrder(String roNumber){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.confirmROrder(roNumber)>0;
        if(flag){
            message.setMessage("更新成功");
            message.setSuccess(flag);
        }else {
            message.setMessage("更新失败");
            message.setSuccess(flag);
        }
        return message;
    }

    public ResponseMessage saleROrder(String roNumber){
        ResponseMessage message = new ResponseMessage();
        Boolean flag = mapper.saleROrder(roNumber)>0;
        if(flag){
            message.setMessage("更新成功");
            message.setSuccess(flag);
        }else {
            message.setMessage("更新失败");
            message.setSuccess(flag);
        }
        return message;
    }
}
